package com.example.demo.controller;

import com.example.demo.constant.Code;
import com.example.demo.error.NoLoginException;
import com.example.demo.pojo.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
public class GlobalExceptionAdvice {
    @ExceptionHandler({Exception.class})
    public R<Void> handleException(Exception e){
        System.out.println("处理exception");
        System.out.println(e);
        return R.error(e.getMessage(),500);
    }

    @ExceptionHandler({NoLoginException.class})
    public R<Void> NoLoginException(Exception e){
        System.out.println("123");
//        System.out.println(e);
        return R.error(e.getMessage(), Code.IllEGAL_TOkEN);
    }
    @ExceptionHandler({org.springframework.dao.DuplicateKeyException.class})
    public R<Void> phoneException(Exception e){
        System.out.println("phone重复");
        System.out.println(e);
        return R.error(e.getMessage(),500);
    }

}
